package com.sina.weibo;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.sina.weibo.models.Account;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class AccountHelper
{
  public static final String PREFS_NICK_NAME = "nickname";
  public static final String PREFS_PASS_WORD = "password";
  public static final String PREFS_USER_FILE = "accounts";
  public static final String PREFS_USER_NAME = "username";

  public static void addOrSortAccount(List<Account> paramList, Account paramAccount)
  {
    Object localObject = null;
    Iterator localIterator = paramList.iterator();
    if (!localIterator.hasNext());
    while (true)
    {
      if (localObject != null)
        boolean bool = paramList.remove(localObject);
      paramList.add(0, paramAccount);
      return;
      Account localAccount = (Account)localIterator.next();
      String str1 = localAccount.user;
      String str2 = paramAccount.user;
      if (!str1.equals(str2))
        break;
      String str3 = paramAccount.pass;
      localAccount.pass = str3;
      String str4 = paramAccount.nick;
      localAccount.nick = str4;
      localObject = localAccount;
    }
  }

  public static Account findAccount(List<Account> paramList, String paramString)
  {
    Account localAccount1 = null;
    Iterator localIterator = paramList.iterator();
    if (!localIterator.hasNext());
    while (true)
    {
      return localAccount1;
      Account localAccount2 = (Account)localIterator.next();
      if (!localAccount2.user.equals(paramString))
        break;
      localAccount1 = new Account();
      String str1 = localAccount2.user;
      localAccount1.user = str1;
      String str2 = localAccount2.pass;
      localAccount1.pass = str2;
      String str3 = localAccount2.nick;
      localAccount1.nick = str3;
    }
  }

  public static List<Account> loadAccounts(Context paramContext)
  {
    SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("accounts", 0);
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    while (true)
    {
      if (i >= 5)
        return localArrayList;
      String str1 = "username" + i;
      String str2 = localSharedPreferences.getString(str1, "");
      String str3 = "password" + i;
      String str4 = localSharedPreferences.getString(str3, "");
      String str5 = "nickname" + i;
      String str6 = localSharedPreferences.getString(str5, "");
      if (str2.length() > 0)
      {
        Account localAccount = new Account();
        localAccount.user = str2;
        localAccount.pass = str4;
        localAccount.nick = str6;
        boolean bool = localArrayList.add(localAccount);
      }
      i += 1;
    }
  }

  public static void saveAccounts(Context paramContext, List<Account> paramList)
  {
    SharedPreferences.Editor localEditor1 = paramContext.getSharedPreferences("accounts", 0).edit();
    SharedPreferences.Editor localEditor2 = localEditor1.clear();
    int i = 0;
    while (true)
    {
      int j = paramList.size();
      if (i >= j)
      {
        boolean bool = localEditor1.commit();
        return;
      }
      String str1 = "username" + i;
      String str2 = ((Account)paramList.get(i)).user;
      SharedPreferences.Editor localEditor3 = localEditor1.putString(str1, str2);
      String str3 = "password" + i;
      String str4 = ((Account)paramList.get(i)).pass;
      SharedPreferences.Editor localEditor4 = localEditor1.putString(str3, str4);
      String str5 = "nickname" + i;
      String str6 = ((Account)paramList.get(i)).nick;
      SharedPreferences.Editor localEditor5 = localEditor1.putString(str5, str6);
      i += 1;
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.AccountHelper
 * JD-Core Version:    0.6.0
 */